package com.b2j.main;

import com.b2j.base.MainTools;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println("Bennu2Java 0.1\nCopyright (C) Proteo 2014");
		
		if (args.length == 0) {
			System.out.println("\n b2j <options> ");
			System.out.println("\t-i\"<Input program file.>\"");
			System.out.println("\t-o\"<Output path.>\"");
			System.out.println("\t-t\"<Temporary path.>\"");
			
		} else {
			
			String input = null;
			String outputPath = null;
			String tempPath = null;
			
			for (int i = 0; i < args.length;i++) {
				
				if (args[i].substring(0, 2).equals("-i"))
					input = args[i].substring(2);
				else if (args[i].substring(0, 2).equals("-o"))
					outputPath = args[i].substring(2);
				else if (args[i].substring(0, 2).equals("-t"))
					tempPath = args[i].substring(2);
				else {
					System.out.println ("ERROR - unexpected \"" + args[i] + "\"");
					System.exit(1);
				}
				
			}

			if (input == null) {
				System.out.println("You must specify the input with the -i option.");
				System.exit(1);
			} else if (outputPath == null) {
				System.out.println("You must specify the output path with the -o option.");		
				System.exit(1);
			} else if (tempPath == null) {
				System.out.println("You must specify the temporary path with the -t option.");		
				System.exit(1);
			}
			
			System.out.println("\nInput: " + input);
			System.out.println("\nOutput Path: " + outputPath);
			System.out.println("\nTemporary Path: " + tempPath);

			MainTools.tools.loadTokenList(input);
			MainTools.tools.buildVariablesList();
			MainTools.tools.buildProcessList();
			MainTools.tools.processCode();
			MainTools.tools.normalizeCode();
			MainTools.tools.generateProgram(outputPath);

		}

	}

}
